using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BarrierPool : MonoBehaviour
{
    public GameObject BarrierPrefab;
    public int poolSize = 1;

    private List<GameObject> objectPool = new List<GameObject>();


    
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < poolSize; i++)
        {
            GameObject enemy = Instantiate(BarrierPrefab, Vector3.zero, Quaternion.identity);
            enemy.SetActive(false);
            objectPool.Add(enemy);
        }
    }

    // Update is called once per frame
    void Update()
    {

    }

    void Create(float Posx, float Posy) {
        GameObject enemy = GetPooledObject();
        if (enemy != null)
        {
            enemy.transform.position = new Vector2(Posx, Posy);
            enemy.SetActive(true);
        }
    }

    GameObject GetPooledObject()
    {
        for (int i = 0; i < objectPool.Count; i++)
        {
            if (!objectPool[i].activeInHierarchy)
            {
                return objectPool[i];
            }
        }
        return null;
    }
}
